package com.heima.cn;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@WebServlet("/ServletStudent")
public class ServletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //从请求中获取数据
        String username = req.getParameter("username");
        String age = req.getParameter("age");
        String soccer = req.getParameter("soccer");
        //将数据写入本地磁盘中
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("D:\\stu.txt",true));
        bufferedWriter.write(username+","+age +","+soccer);
        bufferedWriter.newLine();
        bufferedWriter.close();
        //响应给用户
        PrintWriter  pw= resp.getWriter();
        pw.write("save");
        pw.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req ,resp);
    }
}
